import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { ItemData } from "../../resource/info/ItemData";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { Language } from "../../../../extend/language/Language";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { DataEvent } from "../../events/DataEvent";
import { EquipmentModuleConst } from "./data/EquipmentModuleConst";
import { MaterialItemData } from "./MaterialItemData";
import { ColorConfig } from "../../resource/ColorConfig";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GButton } from "../../../../com/mui/controls/GButton";
import { ShopItemInfo } from "../../resource/info/ShopItemInfo";
import { _buyItemInfo } from "../../../../this/_buyItemInfo";
//class MaterialItemCellRenderer
    
    export  class MaterialItemCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initStyle();
            this.createChildren();
            this.mouseChildren = true;
            return;
        }

        protected initStyle(): void
        {
            var loc1=GlobalClass.getBitmap("equipment_over");
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        protected createChildren(): void
        {
            this.cellBg = ObjCreate.createBg(0, 0, 128, 58, this, ImagesConst.DisabledBg);
            this.picBg = GlobalClass.getBitmap("PackItemBg");
            this.picBg.y = 18;
            this.picBg.x = 1;
            addChild(this.picBg);
            this.pic = new BaseItem();
            this.pic.isDragAble = false;
            this.pic.isThrowAble = false;
            this.pic.isDropAble = false;
            this.pic.isShowLock = true;
            this.pic.setSize(32, 32);
            this.pic.y = 21;
            this.pic.x = 4;
            this.pic.toolTipType = ItemData.ToolTipType_Forge;
            addChild(this.pic);
            this.itemNameLabel = new GLabel();
            this.itemNameLabel.htmlText = Language.getString(60329);
            this.itemNameLabel.x = 1;
            this.itemNameLabel.y = 1;
            this.itemNameLabel.width = 120;
            this.itemNameLabel.height = 20;
            this.itemNameLabel.mouseEnabled = false;
            addChild(this.itemNameLabel);
            this.pricetext = ObjCreate.createLabel(Language.getString(60330), 40, 18, 50, 20, flash.text.TextFormatAlign.LEFT, this, false, 11661311);
            this.pricetext.mouseEnabled = false;
            this.pricetext.drawNow();
            this.priceLabel = ObjCreate.createLabel("96", 70, 18, 45, 20, flash.text.TextFormatAlign.LEFT, this, false, 16770671);
            this.priceLabel.mouseEnabled = false;
            this.yb = GlobalClass.getBitmap(ImagesConst.Yuanbao);
            this.yb.x = 100;
            this.yb.y = 17;
            this.addChild(this.yb);
            this.numStepper = new GNumericStepper();
            this.numStepper.setSize(49, 22);
            this.numStepper.move(40, 34);
            this.numStepper.styleName = "NumericStepper";
            this.numStepper.drawNow();
            this.numStepper.textField.setStyle("upSkin", ResouceConst.getScaleBitmap("DisabledBg"));
            this.numStepper.textField.drawNow();
            this.numStepper.maximum = 99;
            this.numStepper.minimum = 1;
            this.addChild(this.numStepper);
            this.buyButton = ObjCreate.createGButton(Language.getString(60331), 89, 34, 38, 22, this);
            this.buyButton.drawNow();
            this.buyButton.addEventListener(flash.events.MouseEvent.CLICK, this.onBuyButtonClick);
            return;
        }

        /* internal  */onBuyButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.dispatchEvent(new DataEvent(EquipmentModuleConst.Event_DoBuyEvent, {"shopItemInfo": _buyItemInfo, "amount": this.numStepper.value}, false, true, true));
            return;
        }

        public get itemData(): ItemData
        {
            return this.pic.itemData;
        }

        public set itemData(arg1: ItemData)
        {
            this._itemData = arg1;
            this.pic.itemData = this._itemData;
            this.pic.amount = 1;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=0;
            var loc2=null;
            var loc3=null;
            var loc4=0;
            if (data && arg1) 
            {
                if ((data as MaterialItemData).itemData.itemCode != (arg1 as MaterialItemData).itemData.itemCode) 
                {
                    this.numStepper.value = 1;
                }
            }
            super.data = arg1;
            if (arg1) 
            {
                loc2 = arg1 as MaterialItemData;
                this.itemData = loc2.itemData;
                loc3 = ColorConfig.instance.getItemColor(this._itemData.itemInfo.item.color);
                this.itemNameLabel.htmlText = HTMLUtil.addColor(this._itemData.itemInfo.item.name + "×" + this._itemData.itemAmount, loc3.color);
                this.updateStatus(loc2.isInShop);
                if (loc2.isInShop) 
                {
                    this._buyItemInfo = loc2.shopItem;
                    if (this._buyItemInfo) 
                    {
                        loc4 = this._buyItemInfo.tshopSell.offer > 0 ? this._buyItemInfo.tshopSell.offer : this._buyItemInfo.tshopSell.price;
                        this.priceLabel.htmlText = HTMLUtil.addColor(String(loc4), "#FFE66F");
                        this.yb.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(this._buyItemInfo.unit));
                    }
                }
            }
            else 
            {
                this.pic.source = null;
            }
            return;
        }

        /* internal  */updateStatus(arg1: Boolean): void
        {
            if (arg1) 
            {
                this.priceLabel.visible = true;
                this.pricetext.visible = true;
                this.buyButton.visible = true;
                this.numStepper.visible = true;
                this.yb.visible = true;
            }
            else 
            {
                this.priceLabel.visible = false;
                this.pricetext.visible = false;
                this.buyButton.visible = false;
                this.numStepper.visible = false;
                this.yb.visible = false;
            }
            return;
        }

        /* internal */ /* var */_source: string;

        protected /* var */cellBg: Object /* flash.display.Bitmap */;

        protected /* var */picBg: Object /* flash.display.Bitmap */;

        protected /* var */pic: BaseItem;

        protected /* var */itemNameLabel: GLabel;

        protected /* var */pricetext: GLabel;

        protected /* var */priceLabel: GLabel;

        protected /* var */buyButton: GButton;

        protected /* var */_itemData: ItemData;

        protected /* var */_buyItemInfo: ShopItemInfo;

        protected /* var */numStepper: GNumericStepper;

        protected /* var */yb: Object /* flash.display.Bitmap */;
    }
